package com.springcloud.message;

import com.springcloud.stock.WebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.cloud.stream.messaging.Source;

/**
 * @author @1998
 * @date 2021-10-28 1007
 * @description 消息生产者：发送消息类
 */
/**该注解自动给我们绑定消息通道，source是stream给我们提供的*/
@EnableBinding(ISource.class)
public class SendService {

    @Autowired
    private ISource source;

    @Autowired
    private WebSocketHandler webSocketHandler;

    public void sendMessage(String msg){
        System.err.println("发送消息："+source.output().send(MessageBuilder.withPayload(msg).build()));
        System.err.println("发送消息："+source.output().send(MessageBuilder.withPayload(msg).build()));
        webSocketHandler.sendMessage(msg);
    }
}
